﻿Imports BUS
Imports DTO

Public Class frmDanhSachDangMuon

    Private Sub frmDanhSachDangMuon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        drvDanhSachSach.DataSource = frmDangNhap.dsSachTrongGio
    End Sub

    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        frmDangNhap.dsSachTrongGio = New List(Of GioSach)
        drvDanhSachSach.DataSource = frmDangNhap.dsSachTrongGio
    End Sub

    Private Sub btnMuon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMuon.Click
        'Tạo ra một phiếu mượn và thêm dữ liệu vào
        Dim pm As New PhieuMuon_DTO
        pm.maTheDG = TheDocGia_BUS.getMaThe(frmDangNhap.user)
        pm.ngayMuon = DateTime.Now
        'Qui định ngày hết hạn là 1 tháng
        pm.ngayHetHan = DateTime.Now.AddMonths(1)

        'Tạo ra một mảng danh sách chi tiết phiếu mượn
        Dim ds As New List(Of ChiTietPhieuMuon_DTO)

        'sao chép các thông tin từ giỏ sách sang mảng chi tiết phiếu mượn
        For Each gs As GioSach In frmDangNhap.dsSachTrongGio
            Dim ct As New ChiTietPhieuMuon_DTO
            ct.maDauSach = DauSach_BUS.getMaDauSach(gs.maSach)
            ct.sLSach = gs.soLuong
            'tiền thế chân là 20% giá của mỗi cuốn sách
            ct.tienTheChan = gs.tienTheChan * 0.2
            ds.Add(ct)
        Next

        PhieuMuon_BUS.themPhieuMuon(pm, ds)
        frmDangNhap.dsSachTrongGio = New List(Of GioSach)
        drvDanhSachSach.DataSource = frmDangNhap.dsSachTrongGio
        MessageBox.Show("Mượn thành công")

    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
End Class